<template>
  <div class="userinfo">
    <div class="layout">
      <div class="left">
        <div class="photo">
          <template v-if="getUserinfo.avatar == undefined">
            <img src="@/assets/avatar.gif" alt="">
          </template>
          <template v-else>
            <img :src="getUserinfo.avatar" alt="">
          </template>
        </div>
        <div class="username">
          <h2 class="title">{{ getUserinfo.nickname }}</h2>
          <el-button style="color: #3f9eff" @click="changeInfo" link>修改个人信息</el-button>
        </div>
      </div>
      <div class="right">
        <ul>
          <li>绑定手机： {{ getUserinfo.phone != null ? getUserinfo.phone : '未绑定' }}</li>
          <li>绑定邮箱： {{ getUserinfo.email != null ? getUserinfo.email : '未绑定' }}</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { getinfo } from '@/api/user'
import { mapGetters } from 'vuex'

export default {
  computed: {
    ...mapGetters(['getUserinfo'])
  },
  async mounted () {
    const result = await getinfo()
    const userinfo = result.data.data
    this.$store.commit('changeUserinfo', userinfo)
  },
  methods: {
    changeInfo () {
      this.$router.push({
        name: 'ChangeUserInfo'
      })
    }
  }
}
</script>

<style scoped>
.userinfo .layout{
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.userinfo .layout .left{
  display: flex;
  align-items: center;
}

.userinfo .layout .left .photo {
  width: 100px;
  height: 100px;
  margin-right: 20px;
}

.userinfo .layout .left .photo img {
  width: 100%;
  border-radius: 50%;
}

.userinfo .layout .left .title {
  font-size: 20px;
  margin-bottom: 10px;
}

.userinfo .layout .right {
  font-size: 14px;
}
.userinfo .layout .right ul li{
  margin-bottom: 8px;
}
</style>
